<?php
	require_once(realpath(dirname(__FILE__)) . "/Baseobj.class.php");
	require_once(realpath(dirname(__FILE__)) . "/Variable.class.php");
	require_once(realpath(dirname(__FILE__)) . "/Reecriture.class.php");
	require_once(realpath(dirname(__FILE__)) . "/../fonctions/nettoyage.php");
	require_once(realpath(dirname(__FILE__)) . "/../fonctions/hierarchie.php");
	require_once(realpath(dirname(__FILE__)) . "/../fonctions/url.php");
	class Dossierdesc extends Baseobj{

		var $id;
		var $dossier;
		var $lang;
		var $titre;
		var $chapo;
		var $description;
		var $postscriptum;

		const TABLE="dossierdesc";
		var $table=self::TABLE;

		var $bddvars = array("id", "dossier", "lang", "titre", "chapo", "description", "postscriptum");

		function __construct($dossier = 0, $lang = 1){
			parent::__construct();

			if($dossier > 0)
 			  $this->charger($dossier, $lang);
		}

		function charger($dossier, $lang=1){
			return $this->getVars("select * from $this->table where dossier=\"$dossier\" and lang=\"$lang\"");
		}

		function charger_id($id){
		     return $this->getVars("select * from $this->table where id=\"$id\"");
		 }

		function getUrl(){
			$urlsite = new Variable("urlsite");
			$rewrite = new Variable("rewrite");
			if($rewrite->valeur){
				$reecriture = new Reecriture();
				$reecriture->charger_param("dossier", "&id_dossier=" . $this->dossier, $this->lang, 1);
				return $urlsite->valeur ."/".$reecriture->url;
			}
			else
				return $urlsite->valeur . "/?fond=dossier&amp;id_dossier=" . $this->dossier;
		}
		
		function reecrire($url = ""){
			
			if($url == ""){
				$url = $this->dossier . "-" . $this->titre . ".html";
			}
			
			$url = eregurl($url);

			$param = "&id_dossier=" . $this->dossier;
			
			$test = new Reecriture();
			if($test->charger($url, $this->lang))
				return 0;
				
			$reecriture = new Reecriture();
			$reecriture->charger_param("dossier", $param, $this->lang, 1);
			if($reecriture->url == $url)
				return 0;
			
			$reecriture->actif = 0;
			$reecriture->maj();
			
			$reecriture = new Reecriture();
			$reecriture->fond = "dossier";
			$reecriture->url = $url;
			$reecriture->param = $param;
			$reecriture->lang = $this->lang;	
			$reecriture->actif = 1;	
			$reecriture->add();
			
		}
	}


?>